/*     */ package com.hp.bon.sgw.util;
/*     */ 
/*     */ import com.google.gson.Gson;
/*     */ import com.google.gson.reflect.TypeToken;
/*     */ import com.hp.bon.sgw.ctrl.SGWAgentInterface;
/*     */ import java.util.Map;
/*     */ import java.util.Properties;
/*     */ import org.jboss.resteasy.client.ProxyFactory;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ public class RmiAgentUtil
/*     */ {
/*  22 */   private static final Logger logger = LoggerFactory.getLogger(RmiAgentUtil.class);
/*     */   private static String angentHostIP;
/*     */   private static String agentPort;
/*  26 */   private static SGWAgentInterface agent = null;
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/*     */   }
/*     */ 
/*     */   public static SGWAgentInterface getAgentInterface()
/*     */   {
/*  65 */     if (agent != null) {
/*  66 */       return agent;
/*     */     }
/*  68 */     Properties props = new Properties();
/*     */     try {
/*  70 */       props.load(RmiAgentUtil.class.getClassLoader().getResourceAsStream("RmiAgent.properties"));
/*     */ 
/*  72 */       angentHostIP = "localhost";
/*  73 */       agentPort = props.getProperty("SGW_jaxrsPort", "6160");
/*  74 */       String ulr = "http://" + angentHostIP + ":" + agentPort + "/man";
/*  75 */       agent = (SGWAgentInterface)ProxyFactory.create(SGWAgentInterface.class, ulr);
/*     */     } catch (Exception e) {
/*  77 */       logger.warn("get SGWAgentInterface error." + e.fillInStackTrace());
/*  78 */       agent = null;
/*     */     }
/*  80 */     return agent;
/*     */   }
/*     */ 
/*     */   public static double[] getCpuMem() {
/*  84 */     SGWAgentInterface agentClient = getAgentInterface();
/*  85 */     if (agentClient == null) {
/*  86 */       return new double[] { 0.0D, 0.0D };
/*     */     }
/*  88 */     String cpuMemVal = agentClient.getCpuMemPerc();
/*  89 */     Map cpuMem = (Map)new Gson().fromJson(cpuMemVal, new TypeToken() {
/*  90 */     }.getType());
/*  91 */     double cpu = 0.0D;
/*  92 */     double mem = 0.0D;
/*     */     try {
/*  94 */       cpu = Double.valueOf((String)cpuMem.get("cpu")).doubleValue();
/*     */     } catch (Exception e) {
/*  96 */       logger.warn("get cpu error." + e.fillInStackTrace());
/*     */     }
/*     */     try {
/*  99 */       mem = Double.valueOf((String)cpuMem.get("mem")).doubleValue();
/*     */     } catch (Exception e) {
/* 101 */       logger.warn("get memory error." + e.fillInStackTrace());
/*     */     }
/* 103 */     return new double[] { cpu, mem };
/*     */   }
/*     */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.sgw.util.RmiAgentUtil
 * JD-Core Version:    0.6.1
 */